import request from '@/utils/request';
import {download, toFormData} from '@/utils/common';

/**
 * 分页查询学籍信息管理
 */
export async function pageInfos(params) {
  const res = await request.get('/admin/school/degree/list', {params});
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加学籍信息管理
 */
export async function addInfo(data) {
  const res = await request.post('/admin/school/degree', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改学籍信息管理
 */
export async function updateInfo(data) {
  const res = await request.put('/admin/school/degree', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除学籍信息管理
 */
export async function removeInfo(id) {
  const res = await request.delete('/admin/school/degree' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除学籍信息管理
 */
export async function removeInfos(ids) {
  const res = await request.delete('/admin/school/degree' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出学籍信息管理
 */
export async function exportInfos(params) {
  const res = await request({
    url: '/admin/school/degree/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  download(res.data, `info_${Date.now()}.xlsx`);
}
